import time
import unittest
from common.open_browser import open_browser
from page.register_page import RegisterPage
from page.index_page import IndexPage


class RegisterTestCase(unittest.TestCase):
    # 前大夹具
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器,默认谷歌
        driver = open_browser()
        driver.maximize_window()
        # 创建RegisterPage对象
        cls.register = RegisterPage(driver)
        cls.index = IndexPage(driver)

    def test1_register(self):
        # 请求网址
        self.register.get('http://172.16.140.48/ecshop/user.php?act=register')
        # 注册操作,继承了,直接调用
        self.register.input_username('xjf9520')
        self.register.input_email('789469@789469.com')
        self.register.input_password('123456')
        self.register.input_confirm_password('123456')
        self.register.input_qq('597001831')
        self.register.input_phone('13554130351')
        self.register.a_drop_down_box(5)
        self.register.input_passwd_answer('海阔天空')
        self.register.input_submit()

        # 断言注册成功
        # 注册成功后的页面显示的用户名,是否和注册时输入的用户账号一样
        username = self.index.font_text()
        self.assertEqual('xjf9520', username)

    # 后大夹子
    @classmethod
    def tearDownClass(cls) -> None:
        # 退出浏览器
        time.sleep(2)
        cls.register.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)